<?php
header("Content-Type:text/html;charset=utf-8");
session_start();
include 'includes/init.php';
// print_r($_SESSION);
$id=isset($_SESSION['id'])?$_SESSION['id']:'';
$nphone = isset($_SESSION['phone']) ? $_SESSION['phone'] : '';
$sql="select * from t_member where id=$id";
$info=$db_Obj->getone($sql);
$data=isset($_POST['data'])?$_POST['data']:'';
// print_r($data);
// die();
if (!empty($data)) {
	$db_Obj->update('t_member', $data, "id='{$id}'");
}
unset($_POST['data']);
if (!empty($_POST)) {
	for ($i=0; $i <count($_POST['type']) ; $i++) {

	$sql = "INSERT INTO t_product (mid,type,size,number,status,currency,nphone,units) VALUES (".$id.",'".$_POST['type'][$i]."','".$_POST['size'][$i]."','".$_POST['number'][$i]."',1,'".$_POST['currency'][$i]."','".$nphone."','".$_POST['units'][$i]."')";
	$db_Obj->query($sql);
	$insertid=$db_Obj->insert_id();

	$time=time();
	$sql2 = "INSERT INTO t_bid (mid,price,createtime,btype,bsize,bnumber,status,rate,delivery,MOQ,MPQ) VALUES (".$id.",'".$_POST['price'][$i]."',".$time.",'".$_POST['type'][$i]."','".$_POST['size'][$i]."',".$_POST['number'][$i].",1,'".$_POST['rate'][$i]."','".$_POST['delivery'][$i]."','".$_POST['MOQ'][$i]."','".$_POST['MPQ'][$i]."')";
	$db_Obj->query($sql2);
	
}
}

$sql="select b.btype,b.bsize,b.bnumber,p.lasttime, min(b.price) as money 
	from t_product as p left join t_bid as b on p.mid=b.mid  
		where b.status=1 and p.lasttime>".time()." order by b.btype";

$infoall=$db_Obj->getall($sql);


?>



<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		body{width: 1200px;margin:0 auto;}
		header{height: 120px;line-height: 120px;background: url(123.png);width: 100%}
		.mydetail{margin-top: 20px;}
		.bid_title{padding-left: 20px;font-weight: bold;height: 30px;line-height: 30px;margin: 30px 0;}
		table {width: 100%;	background-color: transparent;	border-collapse: collapse;border-spacing: 0;}
		.mydetail{padding-bottom: 50px;border-bottom: 1px dashed #000}
		.mydetail th, .mydetail td {border: 1px solid #e2e2e2;text-align: center;	padding: 10px 5px;}
		.bid td,.bid th {border: 1px solid #e2e2e2;text-align: center;	padding: 10px 5px;}
		.tal{text-align: left;}
		.tac{text-align: center;}
		.bid{background: #F4F9FD}
		.bid_con input.long{margin:8px 4px;height: 25px;line-height: 25px;width: 80%;}
		.bid_con input.btn{margin-right: 30px}
		.info_ti{width: 80px;display: inline-block;margin-left: 20px}
	</style>
	<script src="jquery-1.7.2.min.js"></script>
</head>
<body>
	<header>
		<h2 class="tac">竞价表</h2>
	</header>
	<div class="bid_title">竞价商品</div>
	<div class="mydetail">		
		<table>
			<tbody>
				<tr style="background: #eee">
					<th width="30%">型号</th>
					<th width="20%">规格</th>
					<th width="15%">数量</th>
					<th width="18%">截至日期</th>
					<th width="17%">目前最低价格</th>
				</tr>
			<?php for ($i=0; $i <count($infoall) ; $i++) {   ?>
				<tr>
					<td><?php echo $infoall[$i]['btype'] ?></td>
					<td><?php echo $infoall[$i]['bsize'] ?></td>
					<td><?php echo $infoall[$i]['bnumber'] ?></td>
					<td><?php echo date('Y-m-d H:i:s',$infoall[$i]['lasttime']) ?></td>
					<td><?php echo $infoall[$i]['money'] ?></td>
					
				</tr>
			<?php } ?>
				
			</tbody>
		</table>
	</div>

		<div class="bid">
		<div class="bid_title">报价表</div>
		<div class="bid_con">
			<form action="" method="post">
				<span class="info_ti">公司名称:</span><input class="long" type="text" name="data[company_name]" value="<?php echo $info['company_name'] ?>"><br>
				<span class="info_ti">联系人:</span><input class="long" type="text" name="data[names]" value="<?php echo $info['names'] ?>"><br>
				<span class="info_ti">电话:</span><input class="long" type="text" name="data[phone]" value="<?php echo $info['phone'] ?>"><br>
				<span class="info_ti">E-mail:</span><input class="long" type="text" name="data[email]" value="<?php echo $info['email'] ?>"><br>
				<span class="info_ti">地址:</span><input class="long" type="text" name="data[company_address]" value="<?php echo $info['company_address'] ?>">
				<table>
					<tbody class="table2">
						<tr style="background: #eee">
							<th width="4%"></th>
							<th width="6%">序号</th>
							<th width="10%">型号</th>
							<th width="10%">规格</th>
							<th width="9%">数量</th>
							<th width="5%">报价</th>
							<th width="10%">税率</th>
							<th width="10%">交期</th>
							<th width="10%">MOQ</th>
							<th width="10%">MPQ</th>
							<th width="10%">单位</th>
							<th width="10%">币种</th>
						</tr>
						<tr class="input_table">
							<td><input class="long" type="checkbox"></td>
							<td class="num">1</td>
							<td><input class="long" type="text" name="type[]"></td>
							<td><input class="long" type="text" name="size[]"></td>
							<td><input class="long" type="text" name="number[]"></td>
							<td><input class="long" type="text" name="price[]"></td>
							<td><input class="long" type="text" name="rate[]"></td>
							<td><input class="long"  name="delivery[]" onclick="laydate()"></td>
							<td><input class="long" type="text" name="MOQ[]"></td>
							<td><input class="long" type="text" name="MPQ[]"></td>
							<td>
								<select name="units[]" id="">
									<option value="个">个</option>
									<option value="只">只</option>
									<option value="箱">箱</option>
								</select>
							</td>
							<td><input class="long" type="text" name="currency[]"></td>
						</tr>
					</tbody>
				</table>
				<div style="margin-top:20px"><input class="btn" type="button" value="增加行" onclick="addRow()"><input class="btn" type="button" value="删除行" onclick="delRow()"></div>
				<div style="text-align:center"><input style="width: 50px;margin-right:20px;" type="submit" value="提交"><input style="width: 50px;" type="reset" value="重置"></div>
			</form>
		</div>
		</div>
		<div style="text-align: right;margin: 50px 0"></div>
	

	<script>
	function addRow () {
		var num = $('tbody.table2>tr').length;
		var addTR = $('tr.input_table:last-child').clone(true);
		addTR.appendTo("tbody.table2");
		addTR.find('input').val('');
		addTR.find('td.num').html(num);
	}
	
	function delRow () {
		if($('tbody.table2>tr').length>2){
		$('tbody.table2>tr:has(:checked)').remove();
		change();
		}
	}
	function change(){
		$('.num').each(function(i){
		$(this).html(i+1);
		})
	}
	</script>
</body>
</html>